﻿using System;
using System.Collections.Generic;
using System.Linq;
namespace MostCommon2
{
    class Program
    {
        //static int mostcommonNumber(string[] array)
        //{
        //    int[] parsedNumbers = new int[array.Length];
        //    for (int index = 0; index < array.Length; index++)
        //    {
        //        parsedNumbers[index] = int.Parse(array[index]);
        //    }

        //    var query = parsedNumbers.GroupBy(item => item).OrderByDescending(g => g.Count()).Select(g => g.Key).First();
        //    return query;
        //}
        static string mostCommonString(string[] array )
        {
            Dictionary<string, int> names = new Dictionary<string, int>();

            int currentMinOccurances = 0;
            string currentString = "";
            for (int index = 0; index < array.Length; index++)
            {
                int count;
                if (!names.TryGetValue(array[index], out count))
                {
                    count = 0;
                }
                names[array[index]] = ++count ;
                if (currentMinOccurances < count)
                {
                    currentMinOccurances = count;
                    currentString = array[index];
                }
                else if (currentMinOccurances == count)
                {
                    if (currentString.CompareTo( array[index]) == 1)
                    {
                        currentString = array[index];
                    }
                }
            }            
            return currentString;
        }

        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            string[][] wordMatrix = new string[6][];
            for (int index = 0; index < 6; index++)
            {
                wordMatrix[index] = new string[n];
            }

            for (int index = 0; index < n; index++)
            {
                string token = Console.ReadLine();
                string[] tokens = token.Split(new char[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries);
                int counter = 0;
                foreach (var item in tokens)
                {
                                                     
                        wordMatrix[counter][index] = item;
                        counter++;
                    
                }
            }


            //Console.WriteLine(mostCommonString(wordMatrix[0]));
            //Console.WriteLine(mostCommonString(wordMatrix[1]));
            //Console.WriteLine(mostcommonNumber(wordMatrix[2]));
            //Console.WriteLine(mostCommonString(wordMatrix[3]));
            //Console.WriteLine(mostCommonString(wordMatrix[4]));
            //Console.WriteLine(mostcommonNumber(wordMatrix[5]));

            for (int index = 0; index < 6; index++)
            {
                Console.WriteLine(mostCommonString(wordMatrix[index]));
            }

            //string[] a = { "5", "7", "5","8", "6", "8", "9", "10","8", "11", "12", "2","9","9" };
            //Console.WriteLine(mostcommonNumber(a));

        }
    }
}
